<?php
class Mysql_dr extends Db{
	private static $ins=null;
	private $cfg=array();
	private $link=null;
	
	protected function __construct(){
		$conf=Conf::getIns();
		$this->cfg=$conf->load_config();
		$this->connect();
	}
	public function __destruct(){
		$this->close();
	}
	public static function getIns(){
        if(!(self::$ins instanceof self)) {
            self::$ins=new self();
        }
        return self::$ins;
    }
	protected function connect(){
		$config_db=$this->cfg['DB'];
		$this->link=mysql_connect($config_db['host'],$config_db['user'],$config_db['pwd']);
		if($this->link){
			$r=mysql_select_db($config_db['db'],$this->link);
			if($r){
				$this->query("set names {$config_db['charset']}");
			}else{
				exit('数据库选择错误！');
			}
		}else{
			exit('数据库连接错误！');
		}
	}
	public function query($query){
		$r=mysql_query($query,$this->link);
		if($msg=$this->err()){
			$pos=$_SESSION['_debug_pos_'];
			$this->_log_err($pos.$msg.$query);
			unset($_SESSION['_debug_pos_']);
		}
		return $r;
	}
	public function err(){
		return mysql_error($this->link);
	}
	public function fetch_array($result,$type){
		return mysql_fetch_array($result,$type);
	}
	public function fetch_row($result){
		return mysql_fetch_row($result);
	}
	public function fetch_assoc($result){
		return mysql_fetch_assoc($result);
	}
	public function free_result($result) {
		return mysql_free_result($result);
	}
	public function insert_id() {
		return mysql_insert_id($this->link);
	}
	public function close(){
		return mysql_close($this->link);
	}
//
}